package com.ycx.ycxmybatismanagement.config;

import com.ycx.ycxmybatismanagement.Interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")   //设置拦截器拦截的请求路径（ /** 表示拦截所有请求）
                .excludePathPatterns("/login");  //放行login请求

    }
    //跨域
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                .allowedOriginPatterns("http://127.0.0.1:5500")//允许的来源
//                .allowedMethods("GET","PSOT")//允许的HTTP方法
//                .allowedHeaders("header1","header2")//允许的请求头
//                .allowCredentials(true);//是否支持凭证
//    }
}
